﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.IO;
using System.Drawing.Imaging;
using System.Net;
using CarLoanSystem.Web.Comman;
using CarLoanSystem.DAL;
using CarLoanSystem.Entity;

namespace CarLoanSystemWeb.Page.CarInfo
{
    public partial class wuc_car_info : UserControlManageForm
    {
        public event EventHandler ErrorMessege;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                BlindDataTable();
            }
            catch (Exception ex)
            {
                if (ErrorMessege != null)
                {
                    ErrorMessege(this, EventArgs.Empty);
                }
            }
        }

        private void BlindDataTable()
        {
            this.gvList.DataSource = CarInfoDAL.LoadAllCarForWeb(this.ddlBrand.SelectedValue.ToString(),this.ddlModel.SelectedValue.ToString());
            this.gvList.DataBind();
            if (gvList.DataSource == null)
            {
                lblAlert.Visible = true;
                gvList.Visible = false;
            }
            else
            {
                lblAlert.Visible = false;
                gvList.Visible = true;
            }
        }

        protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvList.PageIndex = e.NewPageIndex;
            gvList.DataBind();
        }

        protected void gvList_EditCommand(object sender, GridViewEditEventArgs e)
        {
            Response.Redirect("ViewCarInfoPage.aspx?id=" + gvList.DataKeys[e.NewEditIndex].Values[0].ToString());
        }
    }
}